<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: dzapp_qrcode.php 33234 2014-11-13 11:49:07Z mpage $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$level = array(
	1 => 'QR_ECLEVEL_L',
	2 => 'QR_ECLEVEL_M',
	3 => 'QR_ECLEVEL_Q',
	4 => 'QR_ECLEVEL_H',
);

$qrdir = 'qrcode/'.substr(md5($_GET['url']), 0, 2).'/'.substr(md5($_GET['url']), 2, 2).'/'.substr(md5($_GET['url']), 4, 2).'/';
$qrfile = $qrdir.substr(md5($_GET['url']), -16).'.png';
if(file_exists($_G['setting']['attachdir'].$qrfile)) {
	dheader('location: '.$_G['setting']['attachurl'].$qrfile);
}

define('NOROBOT', TRUE);
dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');

dmkdir($_G['setting']['attachdir'].'/'.$qrdir);
require_once DISCUZ_ROOT.'source/plugin/dzapp_base/class/class_qrcode.php';
$qrurl = $_GET['ispay'] == 1 ? urldecode($_GET['url']) : $_G['siteurl'].urldecode($_GET['url']);
QRcode::png($qrurl, $_G['setting']['attachdir'].$qrfile, $level[$_G['setting']['dzapp_base_qrcode_level']], $_G['setting']['dzapp_base_qrcode_size']);

dheader('location: '.$_G['setting']['attachurl'].$qrfile);

?>